import 'package:flutter/material.dart';
import 'package:news_demo/Pojo/Email_Persion_Pojo.dart';

import '../../Email/Email.dart';

class Information extends StatefulWidget {
  late final userValueList;
  Information({Key? key,required this.userValueList}) : super(key: key);

  @override
  State<Information> createState() => _IndexState(userValueList: userValueList);
}

class _IndexState extends State<Information> {
  _IndexState({required this.userValueList});
  late final List<String> _titleValueList;

  late final List<IconData> _titleIconList;

  late final List<Widget> _titleList = [];

  late final List<Widget> _EmailList=[];

  late final List<emailPersion> userValueList;


  @override
  void initState() {
    // TODO: implement initState
    super.initState();



    _titleValueList = [
      "系统信息",
      "回复我的",
      "点赞我的",
    ];
    _titleIconList=[
      Icons.notifications_active,
      Icons.chat,
      Icons.thumb_up
    ];

    //处理顶部选择
    for (int i = 0; i < _titleValueList.length; i++) {
      _titleList.add(
        GestureDetector(
          onTap: (){

          },
            //系统通知
            child: Container(
          height: 80,
          width: 80,
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Container(
                child: Icon(
                  _titleIconList[i],
                  size: 58,
                  color: Colors.blue,
                ),
              ),
              Text(
                _titleValueList[i],
                style: TextStyle(fontSize: 12, color: Colors.black),
              )
            ],
          ),
        )),
      );
    }

    //处理信息展示
    for(int i=0;i<userValueList.length;i++){
      _EmailList.add(
        Email(userValue:userValueList[i],),
      );
      _EmailList.add(Divider());
    }
  }




  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        toolbarHeight: 100,
        backgroundColor: Colors.white,
        title: Container(
          height: 100,
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: _titleList,
          ),
        ),
      ),
      body: SingleChildScrollView(
        scrollDirection: Axis.vertical,
        child: Container(
          width: double.infinity,
          child: Column(
            children: _EmailList,
          ),
        ),
      ),
    );
  }
}

//信息展示组件

class Email extends StatefulWidget {
  late final emailPersion userValue;
  Email({Key? key, required this.userValue}) : super(key: key);

  @override
  State<Email> createState() => _EmailState(userValue: this.userValue);
}

class _EmailState extends State<Email> {
  _EmailState({required this.userValue});
  late final emailPersion userValue;
  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: (){
        Navigator.push(context, MaterialPageRoute(builder: (context)=> EmailIn(userValue: userValue,)));
      },
      child: Container(
          width: double.infinity,
          height: 70,
          margin: EdgeInsets.all(6),
          child: ListTile(
            leading: Image.network(userValue.logoUrl),
            //名字
            title: Container(
              child: Text(
                userValue.name,
                maxLines: 1,
                overflow: TextOverflow.ellipsis,
              ),
              margin: EdgeInsets.fromLTRB(0, 0, 0, 8),
            ),
            //信息
            subtitle: Text(
              userValue.oneInformation,
              maxLines: 1,
              overflow: TextOverflow.ellipsis,),
            //时间
            trailing: Text(userValue.time),
          )
      ),
    );
  }
}


